package com.ruoyi.business.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class AliBaBaBankCatd {


    public static boolean backCard(String accountNo,String bankPreMobile,String idCardCode,String name) {
        String host = "https://zball.market.alicloudapi.com";
        String path = "/v2/bcheck";
        String method = "POST";
        String appcode = "1aa8725c1fe34351a2cebe2b4390a977";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("accountNo", accountNo);
        bodys.put("bankPreMobile", bankPreMobile);
        bodys.put("idCardCode", idCardCode);
        bodys.put("name", name);


        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
            String entity = EntityUtils.toString(response.getEntity());
            System.out.println(entity);
            Map map = JSON.parseObject(entity.toString(),Map.class);
            JSONObject result =(JSONObject)map.get("result");
            String respCode =(String) result.get("respCode");
            if(respCode.equals("T")){
                return true;
            }
            /* System.out.println(EntityUtils.toString(response.getEntity()));*/
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return false;
    }

    public static void main(String[] args) {
        boolean codePay =AliBaBaBankCatd.backCard("6228412063013163465","17530870650","410482200301067719","武奕哲");
        System.out.println(codePay);
    }
}
